package crypto.GM;

import org.bouncycastle.crypto.digests.SM3Digest;
import org.bouncycastle.util.encoders.Hex;

import java.io.UnsupportedEncodingException;

public class SM3Util {
    public static byte[] sm3(byte[] bytes) {
        SM3Digest sm3 = new SM3Digest();
        sm3.update(bytes, 0, bytes.length);
        byte[] result = new byte[sm3.getDigestSize()];
        sm3.doFinal(result, 0);
        return result;
    }

    public static void main(String[]args) throws UnsupportedEncodingException {
        String sign="{\"msgHead\": {\"orgSenderID\": \"0000000179\", \"charSet\": \"UTF-8\", \"orgSendTransID\": \"000000017920220325170337330455\", \"orgSendDate\": \"20220325\", \"orgReceiverID\": \"0000000055\", \"versionID\": \"1.0\", \"orgSendTime\": \"170337\"}, \"msgBody\": {\"notifySystemNo\": \"QingFen\", \"notifyProjectNo\": \"DingShi\", \"notifyTitle\": \"\\u544a\\u8b66\\u6d4b\\u8bd5\", \"srcNotifyId\": \"61777\", \"notifyContent\": \" \\u544a\\u8b66\\u6d4b\\u8bd5 {{ \\nalert.strategy.trigger.compare_desc_text }}\\uff0c\\u65f6\\u95f4:2022\\u5e743\\u670825\\u65e5 17:09:37 \", \"notifyTypeNo\": \"\\u9884\\u8b66\"}}1234567890ABCDEFFEDCBA0987654321";
        String sign2="hello";
//        System.out.println(Base64.toBase64String(sm3("hello".getBytes())));
        System.out.println(Hex.toHexString(sm3(sign.getBytes("UTF-8"))) );
        System.out.println(Hex.toHexString(sm3(sign.getBytes())) );
//        System.out.println(ByteUtils.toHexString(sm3(sign.getBytes())) );

//        String base = "y7dzL3fYo2KjcpdpPgpzjmSbfXg7FsZalIbWCJpcXyQ=";
//        String s = Hex.toHexString(Base64.decode(base.getBytes()));
//        System.out.println(s);

    }
}

